home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.2)
-
- '''
- /***************************************************************************
-
- \tAuthor \t\t\t:Charles B. Cosse
- \t
- \tEmail\t\t\t:ccosse@asymptopia.com
- \t\t\t\t\t
- \t\t\t\t\t
- \tCopyright\t\t:(C) 2002,2003 Asymptopia Software.
- \t
- ***************************************************************************/
- /***************************************************************************
- Localizer.py
-
-
- ***************************************************************************/
-
- /***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. (Please note that if you use this *
- * code you must give credit by including the Author and Copyright *
- * info at the top of this file). *
- ***************************************************************************/
-
- '''
- import pygame
- import os
- from pygame.locals import *
- from random import random
-
- class Localizer:
- '''Localizer has game model.
- \t'''
-
- def __init__(self, board, game):
- self.board = board
- self.game = game
- self.board_map = None
- self.M = self.board.M
- self.N = self.board.N
-
-
- def update_board_map(self):
- self.board_map = self.board.get_map()
-
-
- def localize(self, submission):
- rand = int(random() * 2)
- if rand == 0:
- rlist = self.try_row(submission)
- if rlist:
- return rlist
-
- rlist = self.try_col(submission)
- if rlist:
- return rlist
-
- else:
- rlist = self.try_col(submission)
- if rlist:
- return rlist
-
- rlist = self.try_row(submission)
- if rlist:
- return rlist
-
- return None
-
-
- def try_row(self, submission):
- board_map = self.board_map
- M = self.M
- N = self.N
- if len(submission) == 0:
- return None
-
- if len(self.board.get_listofheads()) == 0:
- return None
-
- slim = len(submission)
- nlim = (N - len(submission)) + 1
- for m in range(M):
- for n in range(nlim):
- ok = 1
- for sidx in range(slim):
- if submission[sidx][:3] == 'WC:':
- if board_map[m][n + sidx] == submission[sidx][3:]:
- dummy = 0
- else:
- ok = 0
- elif board_map[m][n + sidx] == '':
- dummy = 0
- else:
- ok = 0
-
- if ok == 1:
- rlist = []
- for idx in range(slim):
- tripple = [
- submission[idx],
- m,
- n + idx]
- rlist.append(tripple)
-
- rval = self.check_neighborhood(rlist)
- tuxscore = 0
- multiplier = 1
- for nn in range(n, n + len(rlist)):
- spot2check = self.board.get_spotMN(m, nn)
- if spot2check.TYPE == '2XL':
- tuxscore = tuxscore + 2
- elif spot2check.TYPE == '2XW':
- tuxscore = tuxscore + 1
- multiplier = multiplier * 2
- elif spot2check.TYPE == '3XL':
- tuxscore = tuxscore + 3
- elif spot2check.TYPE == '3XW':
- tuxscore = tuxscore + 1
- multiplier = multiplier * 3
- else:
- tuxscore = tuxscore + 1
-
- tuxscore = tuxscore * multiplier
- for idx in range(slim - 1, -1, -1):
- if rlist[idx][0][:3] == 'WC:':
- rlist.pop(idx)
-
-
- if rval == 1:
- self.game.tuxscore = self.game.tuxscore + tuxscore
- return rlist
-
-
-
-
- return None
-
-
- def try_col(self, submission):
- board_map = self.board_map
- M = self.M
- N = self.N
- if len(submission) == 0:
- return None
-
- if len(self.board.get_listofheads()) == 0:
- return None
-
- slim = len(submission)
- mlim = (M - len(submission)) + 1
- for n in range(N):
- for m in range(mlim):
- ok = 1
- for sidx in range(slim):
- if submission[sidx][:3] == 'WC:':
- if board_map[m + sidx][n] == submission[sidx][3:]:
- dummy = 0
- else:
- ok = 0
- elif board_map[m + sidx][n] == '':
- dummy = 0
- else:
- ok = 0
-
- if ok == 1:
- rlist = []
- for idx in range(slim):
- tripple = [
- submission[idx],
- m + idx,
- n]
- rlist.append(tripple)
-
- rval = self.check_neighborhood(rlist)
- tuxscore = 0
- multiplier = 1
- for mm in range(m, m + len(rlist)):
- spot2check = self.board.get_spotMN(mm, n)
- if spot2check.TYPE == '2XL':
- tuxscore = tuxscore + 2
- elif spot2check.TYPE == '2XW':
- tuxscore = tuxscore + 1
- multiplier = multiplier * 2
- elif spot2check.TYPE == '3XL':
- tuxscore = tuxscore + 3
- elif spot2check.TYPE == '3XW':
- tuxscore = tuxscore + 1
- multiplier = multiplier * 3
- else:
- tuxscore = tuxscore + 1
-
- tuxscore = tuxscore * multiplier
- for idx in range(slim - 1, -1, -1):
- if rlist[idx][0][:3] == 'WC:':
- rlist.pop(idx)
-
-
- if rval == 1:
- self.game.tuxscore = self.game.tuxscore + tuxscore
- return rlist
-
-
-
-
- return None
-
-
- def check_neighborhood(self, rlist):
- board_map = self.board_map
- M = self.M
- N = self.N
- ok = 1
- slen = len(rlist)
- head = (rlist[0][1], rlist[0][2])
- tail = (rlist[slen - 1][1], rlist[slen - 1][2])
- if rlist[0][2] == rlist[1][2]:
- iscol = 1
- col = rlist[0][2]
- else:
- iscol = 0
- row = rlist[0][1]
- if iscol:
- if head[0] == 0:
- pass
- elif board_map[head[0] - 1][col] != '':
- ok = -1
- return ok
-
- if tail[0] == M - 1:
- pass
- elif board_map[tail[0] + 1][col] != '':
- ok = -2
- return ok
-
- if col == 0:
- pass
- else:
- for qty in rlist:
- if qty[0][:3] == 'WC:':
- pass
- elif board_map[qty[1]][col - 1] != '':
- ok = -3
- return ok
-
-
- if col == N - 1:
- pass
- else:
- for qty in rlist:
- if qty[0][:3] == 'WC:':
- pass
- elif board_map[qty[1]][col + 1] != '':
- ok = -4
- return ok
-
-
- elif head[1] == 0:
- pass
- elif board_map[row][head[1] - 1] != '':
- ok = -5
- return ok
-
- if tail[1] == N - 1:
- pass
- elif board_map[row][tail[1] + 1] != '':
- ok = -6
- return ok
-
- if row == 0:
- pass
- else:
- for qty in rlist:
- if qty[0][:3] == 'WC:':
- pass
- elif board_map[row - 1][qty[2]] != '':
- ok = -7
- return ok
-
-
- if head[0] == M - 1:
- pass
- else:
- for qty in rlist:
- if qty[0][:3] == 'WC:':
- pass
- elif board_map[row + 1][qty[2]] != '':
- ok = -8
- return ok
-
-
- return ok
-
-
-